home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Date: 3 Apr 1996 08:09:18 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4ju7reINN3bd@keats.ugrad.cs.ubc.ca>
- References: <31616F63.481D@lava.weeg.uiowa.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <31616F63.481D@lava.weeg.uiowa.edu>,
- Artur Wojdat <awojdat@lava.weeg.uiowa.edu> wrote:
- >Hello everybody,
- > Is there a function or some sort of way that I could remove '\n'
- >charecter form the end of the string. I'm reading from two files, want to
- >form one line of text and then have it printed out to stdout. I use fgets to
- >read from the file and I noticed that it appends newline char at the end.
- > It is important that two lines of text, one from each file, will be
- >combined into one and I can't do it because the first string has '\n' added
- >to it. I'm picky becauuse the output will be used to feed another program and
- >I'm affraid that not properly formatted input may corrupt the process.
- > Any suggestions will be greatly appreciated .. Thanks, Art ...
-
- For this sort of problem, a character-oriented approach is perhaps best. What
- you are asking for can be solved by a regular expression automaton. It would be
- foolish to read whole lines into buffers and process that way, since this
- problem does not call for more than one character of lookahead! In fact, it
- calls for no lookahead at all! Only a fool would try to read lines from the
- standard IO library into yet another buffer and then do string operations.
-
- Just read a character from one file using c = getc(stream) and use putchar(c)
- to put it onto the standard output unless c is EOF or '\n', in which case you
- switch to the second file and do the same thing. You repeat until both files
- reach EOF. No silly-willy string buffering and concatenation needed. In any
- case, fgets() calls for a fixed-size buffer, so your program would not be
- robust for files with long lines unless you took extra care that would further
- complicate your program needlessly.
-
-
-
-
-
-
-
-
-
-
-
- --
-
-